package com.healthcloud.utils;

import org.apache.shiro.crypto.hash.DefaultHashService;
import org.apache.shiro.crypto.hash.HashRequest;

/**
 * Created by houxianghua on 2015/8/6.
 */
public abstract class UserUtil {

    public static String encryptPassword(Object plaintext) {
        DefaultHashService hashService = new DefaultHashService(); //默认算法SHA-512
        hashService.setHashAlgorithmName("MD5");
        hashService.setGeneratePublicSalt(false);//是否生成公盐，默认false
        hashService.setHashIterations(1); //生成Hash值的迭代次数
        HashRequest request = new HashRequest.Builder()
                .setAlgorithmName("MD5").setSource(plaintext)
                .setIterations(1).build();
        String hex = hashService.computeHash(request).toString();
        return hex;
    }
}
